home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2000 March / maximum-cd-2000-03.iso / Quake3 Game Source / Q3AGameSource.exe / Main / ui_removebots.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-18  |  9.5 KB  |  323 lines

  1. // Copyright (C) 1999-2000 Id Software, Inc.
  2. //
  3. /*
  4. =======================================================================
  5.  
  6. REMOVE BOTS MENU
  7.  
  8. =======================================================================
  9. */
  10.  
  11.  
  12. #include "ui_local.h"
  13.  
  14.  
  15. #define ART_BACKGROUND        "menu/art/addbotframe"
  16. #define ART_BACK0            "menu/art/back_0"
  17. #define ART_BACK1            "menu/art/back_1"    
  18. #define ART_DELETE0            "menu/art/delete_0"
  19. #define ART_DELETE1            "menu/art/delete_1"
  20. #define ART_ARROWS            "menu/art/arrows_vert_0"
  21. #define ART_ARROWUP            "menu/art/arrows_vert_top"
  22. #define ART_ARROWDOWN        "menu/art/arrows_vert_bot"
  23.  
  24. #define ID_UP                10
  25. #define ID_DOWN                11
  26. #define ID_DELETE            12
  27. #define ID_BACK                13
  28. #define ID_BOTNAME0            20
  29. #define ID_BOTNAME1            21
  30. #define ID_BOTNAME2            22
  31. #define ID_BOTNAME3            23
  32. #define ID_BOTNAME4            24
  33. #define ID_BOTNAME5            25
  34. #define ID_BOTNAME6            26
  35.  
  36.  
  37. typedef struct {
  38.     menuframework_s    menu;
  39.  
  40.     menutext_s        banner;
  41.     menubitmap_s    background;
  42.  
  43.     menubitmap_s    arrows;
  44.     menubitmap_s    up;
  45.     menubitmap_s    down;
  46.  
  47.     menutext_s        bots[7];
  48.  
  49.     menubitmap_s    delete;
  50.     menubitmap_s    back;
  51.  
  52.     int                numBots;
  53.     int                baseBotNum;
  54.     int                selectedBotNum;
  55.     char            botnames[7][32];
  56.     int                botClientNums[MAX_BOTS];
  57. } removeBotsMenuInfo_t;
  58.  
  59. static removeBotsMenuInfo_t    removeBotsMenuInfo;
  60.  
  61.  
  62. /*
  63. =================
  64. UI_RemoveBotsMenu_SetBotNames
  65. =================
  66. */
  67. static void UI_RemoveBotsMenu_SetBotNames( void ) {
  68.     int        n;
  69.     char    info[MAX_INFO_STRING];
  70.  
  71.     for ( n = 0; (n < 7) && (removeBotsMenuInfo.baseBotNum + n < removeBotsMenuInfo.numBots); n++ ) {
  72.         trap_GetConfigString( CS_PLAYERS + removeBotsMenuInfo.botClientNums[removeBotsMenuInfo.baseBotNum + n], info, MAX_INFO_STRING );
  73.         Q_strncpyz( removeBotsMenuInfo.botnames[n], Info_ValueForKey( info, "n" ), sizeof(removeBotsMenuInfo.botnames[n]) );
  74.         Q_CleanStr( removeBotsMenuInfo.botnames[n] );
  75.     }
  76.  
  77. }
  78.  
  79.  
  80. /*
  81. =================
  82. UI_RemoveBotsMenu_DeleteEvent
  83. =================
  84. */
  85. static void UI_RemoveBotsMenu_DeleteEvent( void* ptr, int event ) {
  86.     if (event != QM_ACTIVATED) {
  87.         return;
  88.     }
  89.  
  90.     trap_Cmd_ExecuteText( EXEC_APPEND, va("kick %i\n", removeBotsMenuInfo.botClientNums[removeBotsMenuInfo.baseBotNum + removeBotsMenuInfo.selectedBotNum]) );
  91. }
  92.  
  93.  
  94. /*
  95. =================
  96. UI_RemoveBotsMenu_BotEvent
  97. =================
  98. */
  99. static void UI_RemoveBotsMenu_BotEvent( void* ptr, int event ) {
  100.     if (event != QM_ACTIVATED) {
  101.         return;
  102.     }
  103.  
  104.     removeBotsMenuInfo.bots[removeBotsMenuInfo.selectedBotNum].color = color_orange;
  105.     removeBotsMenuInfo.selectedBotNum = ((menucommon_s*)ptr)->id - ID_BOTNAME0;
  106.     removeBotsMenuInfo.bots[removeBotsMenuInfo.selectedBotNum].color = color_white;
  107. }
  108.  
  109.  
  110. /*
  111. =================
  112. UI_RemoveAddBotsMenu_BackEvent
  113. =================
  114. */
  115. static void UI_RemoveBotsMenu_BackEvent( void* ptr, int event ) {
  116.     if (event != QM_ACTIVATED) {
  117.         return;
  118.     }
  119.     UI_PopMenu();
  120. }
  121.  
  122.  
  123. /*
  124. =================
  125. UI_RemoveBotsMenu_UpEvent
  126. =================
  127. */
  128. static void UI_RemoveBotsMenu_UpEvent( void* ptr, int event ) {
  129.     if (event != QM_ACTIVATED) {
  130.         return;
  131.     }
  132.  
  133.     if( removeBotsMenuInfo.baseBotNum > 0 ) {
  134.         removeBotsMenuInfo.baseBotNum--;
  135.         UI_RemoveBotsMenu_SetBotNames();
  136.     }
  137. }
  138.  
  139.  
  140. /*
  141. =================
  142. UI_RemoveBotsMenu_DownEvent
  143. =================
  144. */
  145. static void UI_RemoveBotsMenu_DownEvent( void* ptr, int event ) {
  146.     if (event != QM_ACTIVATED) {
  147.         return;
  148.     }
  149.  
  150.     if( removeBotsMenuInfo.baseBotNum + 7 < removeBotsMenuInfo.numBots ) {
  151.         removeBotsMenuInfo.baseBotNum++;
  152.         UI_RemoveBotsMenu_SetBotNames();
  153.     }
  154. }
  155.  
  156.  
  157. /*
  158. =================
  159. UI_RemoveBotsMenu_GetBots
  160. =================
  161. */
  162. static void UI_RemoveBotsMenu_GetBots( void ) {
  163.     int        numPlayers;
  164.     int        isBot;
  165.     int        n;
  166.     char    info[MAX_INFO_STRING];
  167.  
  168.     trap_GetConfigString( CS_SERVERINFO, info, sizeof(info) );
  169.     numPlayers = atoi( Info_ValueForKey( info, "sv_maxclients" ) );
  170.     removeBotsMenuInfo.numBots = 0;
  171.  
  172.     for( n = 0; n < numPlayers; n++ ) {
  173.         trap_GetConfigString( CS_PLAYERS + n, info, MAX_INFO_STRING );
  174.  
  175.         isBot = atoi( Info_ValueForKey( info, "skill" ) );
  176.         if( !isBot ) {
  177.             continue;
  178.         }
  179.  
  180.         removeBotsMenuInfo.botClientNums[removeBotsMenuInfo.numBots] = n;
  181.         removeBotsMenuInfo.numBots++;
  182.     }
  183. }
  184.  
  185.  
  186. /*
  187. =================
  188. UI_RemoveBots_Cache
  189. =================
  190. */
  191. void UI_RemoveBots_Cache( void ) {
  192.     trap_R_RegisterShaderNoMip( ART_BACKGROUND );
  193.     trap_R_RegisterShaderNoMip( ART_BACK0 );
  194.     trap_R_RegisterShaderNoMip( ART_BACK1 );
  195.     trap_R_RegisterShaderNoMip( ART_DELETE0 );
  196.     trap_R_RegisterShaderNoMip( ART_DELETE1 );
  197. }
  198.  
  199.  
  200. /*
  201. =================
  202. UI_RemoveBotsMenu_Init
  203. =================
  204. */
  205. static void UI_RemoveBotsMenu_Init( void ) {
  206.     int        n;
  207.     int        count;
  208.     int        y;
  209.  
  210.     memset( &removeBotsMenuInfo, 0 ,sizeof(removeBotsMenuInfo) );
  211.     removeBotsMenuInfo.menu.fullscreen = qfalse;
  212.     removeBotsMenuInfo.menu.wrapAround = qtrue;
  213.  
  214.     UI_RemoveBots_Cache();
  215.  
  216.     UI_RemoveBotsMenu_GetBots();
  217.     UI_RemoveBotsMenu_SetBotNames();
  218.     count = removeBotsMenuInfo.numBots < 7 ? removeBotsMenuInfo.numBots : 7;
  219.  
  220.     removeBotsMenuInfo.banner.generic.type        = MTYPE_BTEXT;
  221.     removeBotsMenuInfo.banner.generic.x            = 320;
  222.     removeBotsMenuInfo.banner.generic.y            = 16;
  223.     removeBotsMenuInfo.banner.string            = "REMOVE BOTS";
  224.     removeBotsMenuInfo.banner.color                = color_white;
  225.     removeBotsMenuInfo.banner.style                = UI_CENTER;
  226.  
  227.     removeBotsMenuInfo.background.generic.type    = MTYPE_BITMAP;
  228.     removeBotsMenuInfo.background.generic.name    = ART_BACKGROUND;
  229.     removeBotsMenuInfo.background.generic.flags    = QMF_INACTIVE;
  230.     removeBotsMenuInfo.background.generic.x        = 320-233;
  231.     removeBotsMenuInfo.background.generic.y        = 240-166;
  232.     removeBotsMenuInfo.background.width            = 466;
  233.     removeBotsMenuInfo.background.height        = 332;
  234.  
  235.     removeBotsMenuInfo.arrows.generic.type        = MTYPE_BITMAP;
  236.     removeBotsMenuInfo.arrows.generic.name        = ART_ARROWS;
  237.     removeBotsMenuInfo.arrows.generic.flags        = QMF_INACTIVE;
  238.     removeBotsMenuInfo.arrows.generic.x            = 200;
  239.     removeBotsMenuInfo.arrows.generic.y            = 128;
  240.     removeBotsMenuInfo.arrows.width                = 64;
  241.     removeBotsMenuInfo.arrows.height            = 128;
  242.  
  243.     removeBotsMenuInfo.up.generic.type            = MTYPE_BITMAP;
  244.     removeBotsMenuInfo.up.generic.flags            = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
  245.     removeBotsMenuInfo.up.generic.x                = 200;
  246.     removeBotsMenuInfo.up.generic.y                = 128;
  247.     removeBotsMenuInfo.up.generic.id            = ID_UP;
  248.     removeBotsMenuInfo.up.generic.callback        = UI_RemoveBotsMenu_UpEvent;
  249.     removeBotsMenuInfo.up.width                    = 64;
  250.     removeBotsMenuInfo.up.height                = 64;
  251.     removeBotsMenuInfo.up.focuspic                = ART_ARROWUP;
  252.  
  253.     removeBotsMenuInfo.down.generic.type        = MTYPE_BITMAP;
  254.     removeBotsMenuInfo.down.generic.flags        = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
  255.     removeBotsMenuInfo.down.generic.x            = 200;
  256.     removeBotsMenuInfo.down.generic.y            = 128+64;
  257.     removeBotsMenuInfo.down.generic.id            = ID_DOWN;
  258.     removeBotsMenuInfo.down.generic.callback    = UI_RemoveBotsMenu_DownEvent;
  259.     removeBotsMenuInfo.down.width                = 64;
  260.     removeBotsMenuInfo.down.height                = 64;
  261.     removeBotsMenuInfo.down.focuspic            = ART_ARROWDOWN;
  262.  
  263.     for( n = 0, y = 120; n < count; n++, y += 20 ) {
  264.         removeBotsMenuInfo.bots[n].generic.type        = MTYPE_PTEXT;
  265.         removeBotsMenuInfo.bots[n].generic.flags    = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
  266.         removeBotsMenuInfo.bots[n].generic.id        = ID_BOTNAME0 + n;
  267.         removeBotsMenuInfo.bots[n].generic.x        = 320 - 56;
  268.         removeBotsMenuInfo.bots[n].generic.y        = y;
  269.         removeBotsMenuInfo.bots[n].generic.callback    = UI_RemoveBotsMenu_BotEvent;
  270.         removeBotsMenuInfo.bots[n].string            = removeBotsMenuInfo.botnames[n];
  271.         removeBotsMenuInfo.bots[n].color            = color_orange;
  272.         removeBotsMenuInfo.bots[n].style            = UI_LEFT|UI_SMALLFONT;
  273.     }
  274.  
  275.     removeBotsMenuInfo.delete.generic.type        = MTYPE_BITMAP;
  276.     removeBotsMenuInfo.delete.generic.name        = ART_DELETE0;
  277.     removeBotsMenuInfo.delete.generic.flags        = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
  278.     removeBotsMenuInfo.delete.generic.id        = ID_DELETE;
  279.     removeBotsMenuInfo.delete.generic.callback    = UI_RemoveBotsMenu_DeleteEvent;
  280.     removeBotsMenuInfo.delete.generic.x            = 320+128-128;
  281.     removeBotsMenuInfo.delete.generic.y            = 256+128-64;
  282.     removeBotsMenuInfo.delete.width              = 128;
  283.     removeBotsMenuInfo.delete.height              = 64;
  284.     removeBotsMenuInfo.delete.focuspic            = ART_DELETE1;
  285.  
  286.     removeBotsMenuInfo.back.generic.type        = MTYPE_BITMAP;
  287.     removeBotsMenuInfo.back.generic.name        = ART_BACK0;
  288.     removeBotsMenuInfo.back.generic.flags        = QMF_LEFT_JUSTIFY|QMF_PULSEIFFOCUS;
  289.     removeBotsMenuInfo.back.generic.id            = ID_BACK;
  290.     removeBotsMenuInfo.back.generic.callback    = UI_RemoveBotsMenu_BackEvent;
  291.     removeBotsMenuInfo.back.generic.x            = 320-128;
  292.     removeBotsMenuInfo.back.generic.y            = 256+128-64;
  293.     removeBotsMenuInfo.back.width                = 128;
  294.     removeBotsMenuInfo.back.height                = 64;
  295.     removeBotsMenuInfo.back.focuspic            = ART_BACK1;
  296.  
  297.     Menu_AddItem( &removeBotsMenuInfo.menu, &removeBotsMenuInfo.background );
  298.     Menu_AddItem( &removeBotsMenuInfo.menu, &removeBotsMenuInfo.banner );
  299.     Menu_AddItem( &removeBotsMenuInfo.menu, &removeBotsMenuInfo.arrows );
  300.     Menu_AddItem( &removeBotsMenuInfo.menu, &removeBotsMenuInfo.up );
  301.     Menu_AddItem( &removeBotsMenuInfo.menu, &removeBotsMenuInfo.down );
  302.     for( n = 0; n < count; n++ ) {
  303.         Menu_AddItem( &removeBotsMenuInfo.menu, &removeBotsMenuInfo.bots[n] );
  304.     }
  305.     Menu_AddItem( &removeBotsMenuInfo.menu, &removeBotsMenuInfo.delete );
  306.     Menu_AddItem( &removeBotsMenuInfo.menu, &removeBotsMenuInfo.back );
  307.  
  308.     removeBotsMenuInfo.baseBotNum = 0;
  309.     removeBotsMenuInfo.selectedBotNum = 0;
  310.     removeBotsMenuInfo.bots[0].color = color_white;
  311. }
  312.  
  313.  
  314. /*
  315. =================
  316. UI_RemoveBotsMenu
  317. =================
  318. */
  319. void UI_RemoveBotsMenu( void ) {
  320.     UI_RemoveBotsMenu_Init();
  321.     UI_PushMenu( &removeBotsMenuInfo.menu );
  322. }
  323.